using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VWASTBAT
    {
        public DataRow Convert2WASTBAT(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryWASTBAT(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["WABMANDANT"] = " ".PadRight(2 ); 
         dwReturn["WABWAKZ"] = " ".PadRight(1 ); 
         dwReturn["WABKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["WABWERK"] = " ".PadRight(3 ); 
         dwReturn["WABABT"] = " ".PadRight(3 ); 
         dwReturn["WABART"] = " ".PadRight(20 ); 
         dwReturn["WABVAR"] = " ".PadRight(2 ); 
         dwReturn["WABWCOL"] = " ".PadRight(10 ); 
         dwReturn["WABSA"] = " ".PadRight(1 ); 
         dwReturn["WABPOS"] = " ".PadRight(0 ); 
         dwReturn["WABWAKZB"] = " ".PadRight(1 ); 
         dwReturn["WABKUNDNRB"] = " ".PadRight(8 ); 
         dwReturn["WABWERKB"] = " ".PadRight(3 ); 
         dwReturn["WABABTB"] = " ".PadRight(3 ); 
         dwReturn["WABARTB"] = " ".PadRight(20 ); 
         dwReturn["WABVARB"] = " ".PadRight(2 ); 
         dwReturn["WABWCOLB"] = " ".PadRight(10 ); 
         dwReturn["WABFDZ"] = " ".PadRight(0 ); 
         dwReturn["WABFAK"] = " ".PadRight(0 ); 
         dwReturn["WABWERKE"] = " ".PadRight(1 ); 
         dwReturn["WABABF"] = " ".PadRight(0 ); 
         dwReturn["WABDISPOKZ"] = " ".PadRight(1 ); 
         dwReturn["WABVFREI"] = " ".PadRight(1 ); 
         dwReturn["WABLAEAEND"] = " ".PadRight(0 ); 
         dwReturn["WABSTGRP"] = " ".PadRight(1 ); 
         dwReturn["WABFILLER"] = " ".PadRight(3 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapWASTBAT(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveWASTBAT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWASTBAT(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapWASTBAT(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertWASTBAT(dwLocal, ITXDBVERSION);
            }
            UpdateWASTBAT(dwLocal);
        }
        public void InsertWASTBAT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO WASTBAT(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryWASTBAT(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM WASTBAT WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM WASTBAT  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "WASTBAT";
            Return = Result;
            return Return;
        }
        public void DeleteWASTBAT(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM WASTBAT   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateWASTBAT(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE WASTBAT SET "
                    +"WABMANDANT= :WABMANDANT,"
                    +"WABWAKZ= :WABWAKZ,"
                    +"WABKUNDNR= :WABKUNDNR,"
                    +"WABWERK= :WABWERK,"
                    +"WABABT= :WABABT,"
                    +"WABART= :WABART,"
                    +"WABVAR= :WABVAR,"
                    +"WABWCOL= :WABWCOL,"
                    +"WABSA= :WABSA,"
                    +"WABPOS= :WABPOS,"
                    +"WABWAKZB= :WABWAKZB,"
                    +"WABKUNDNRB= :WABKUNDNRB,"
                    +"WABWERKB= :WABWERKB,"
                    +"WABABTB= :WABABTB,"
                    +"WABARTB= :WABARTB,"
                    +"WABVARB= :WABVARB,"
                    +"WABWCOLB= :WABWCOLB,"
                    +"WABFDZ= :WABFDZ,"
                    +"WABFAK= :WABFAK,"
                    +"WABWERKE= :WABWERKE,"
                    +"WABABF= :WABABF,"
                    +"WABDISPOKZ= :WABDISPOKZ,"
                    +"WABVFREI= :WABVFREI,"
                    +"WABLAEAEND= :WABLAEAEND,"
                    +"WABSTGRP= :WABSTGRP,"
                    +"WABFILLER= :WABFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("WABMANDANT", OracleType.NVarChar).Value = dwData["WABMANDANT"].ToString(); 
          or1.Parameters.Add("WABWAKZ", OracleType.NVarChar).Value = dwData["WABWAKZ"].ToString(); 
          or1.Parameters.Add("WABKUNDNR", OracleType.NVarChar).Value = dwData["WABKUNDNR"].ToString(); 
          or1.Parameters.Add("WABWERK", OracleType.NVarChar).Value = dwData["WABWERK"].ToString(); 
          or1.Parameters.Add("WABABT", OracleType.NVarChar).Value = dwData["WABABT"].ToString(); 
          or1.Parameters.Add("WABART", OracleType.NVarChar).Value = dwData["WABART"].ToString(); 
          or1.Parameters.Add("WABVAR", OracleType.NVarChar).Value = dwData["WABVAR"].ToString(); 
          or1.Parameters.Add("WABWCOL", OracleType.NVarChar).Value = dwData["WABWCOL"].ToString(); 
          or1.Parameters.Add("WABSA", OracleType.NVarChar).Value = dwData["WABSA"].ToString(); 
          or1.Parameters.Add("WABPOS", OracleType.NVarChar).Value = dwData["WABPOS"].ToString(); 
          or1.Parameters.Add("WABWAKZB", OracleType.NVarChar).Value = dwData["WABWAKZB"].ToString(); 
          or1.Parameters.Add("WABKUNDNRB", OracleType.NVarChar).Value = dwData["WABKUNDNRB"].ToString(); 
          or1.Parameters.Add("WABWERKB", OracleType.NVarChar).Value = dwData["WABWERKB"].ToString(); 
          or1.Parameters.Add("WABABTB", OracleType.NVarChar).Value = dwData["WABABTB"].ToString(); 
          or1.Parameters.Add("WABARTB", OracleType.NVarChar).Value = dwData["WABARTB"].ToString(); 
          or1.Parameters.Add("WABVARB", OracleType.NVarChar).Value = dwData["WABVARB"].ToString(); 
          or1.Parameters.Add("WABWCOLB", OracleType.NVarChar).Value = dwData["WABWCOLB"].ToString(); 
          or1.Parameters.Add("WABFDZ", OracleType.NVarChar).Value = dwData["WABFDZ"].ToString(); 
          or1.Parameters.Add("WABFAK", OracleType.NVarChar).Value = dwData["WABFAK"].ToString(); 
          or1.Parameters.Add("WABWERKE", OracleType.NVarChar).Value = dwData["WABWERKE"].ToString(); 
          or1.Parameters.Add("WABABF", OracleType.NVarChar).Value = dwData["WABABF"].ToString(); 
          or1.Parameters.Add("WABDISPOKZ", OracleType.NVarChar).Value = dwData["WABDISPOKZ"].ToString(); 
          or1.Parameters.Add("WABVFREI", OracleType.NVarChar).Value = dwData["WABVFREI"].ToString(); 
          or1.Parameters.Add("WABLAEAEND", OracleType.NVarChar).Value = dwData["WABLAEAEND"].ToString(); 
          or1.Parameters.Add("WABSTGRP", OracleType.NVarChar).Value = dwData["WABSTGRP"].ToString(); 
          or1.Parameters.Add("WABFILLER", OracleType.NVarChar).Value = dwData["WABFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
